package GiaoDien;

import it.unipr.ce.dsg.s2p.sip.Address;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Panel;

import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import DTO.AccountDTO;
import Network.Class_GV_Send_Receive;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public class frm_ThaoLuanNhom extends JFrame {

	Class_GV_Send_Receive peer;
	private JPanel contentPane;
	private String _voteKickMember;
	public String IP;
	String ipBeKick="MES@192.168.1.77:5033";
	String userNameBeKick="truc";
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frm_ThaoLuanNhom frame = new frm_ThaoLuanNhom();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public void ThongBao(String s)
	{
		Object[] optionsNoDN = {"Đóng","Mở","OK","Cancel"};
		
		JOptionPane.showOptionDialog(new JPanel(),//combonent(frm/panel)
				s,//object message
			    "Thông Báo",//title
			    JOptionPane.DEFAULT_OPTION,//option type//thay doi cai khac cung ko thay khac gi ca
			    JOptionPane.INFORMATION_MESSAGE,
			    //WARNING_MESSAGE : biểu tượng hình dấu chấm than trong tam giác
			    //PLAIN_MESSAGE : ko có biểu tượng
			    //ERROR_MESSAGE : biểu tượng hình dấu chéo trong ô lục giác
			    //INFORMATION_MESSAGE : biểu tượng chữ i trong hình tròn
			    //message type==thay đổi biểu tượng của messagebox
			    null,//icon
			    optionsNoDN,//mảng các button sẽ hiển thị
			    optionsNoDN[1]);//button focus vào lúc hiển thị
		
		
	}
	public void ShowSetTimeVoteKick(){
		JFrame frame=new JFrame();
		
		final JTextField txt1=new JTextField();
		txt1.setColumns(1);
		frame.add(txt1);
		String sss=(String)JOptionPane.showInputDialog(frame,
                "Nhập thời gian yêu cầu biểu quyết\n"
                + "\"Thời gian được tính bằng giây\"",
                "Nhập thời gian",
                JOptionPane.PLAIN_MESSAGE,
                null,
                null,
                null);
		
		if(isInteger(sss)){
			int time=Integer.parseInt(sss);
//			frmBieuQuyetMoiRaKhoiNhom f=new frmBieuQuyetMoiRaKhoiNhom(this, peer.getAccount().get_Username(), peer.getAddressPeer(), userNameBeKick, ipBeKick, time);
//			f.setVisible(true);
			peer.SendVoteKickMember(new Address(ipBeKick), time);
		    return;
		}

	}
	
    public boolean isInteger( String input )  
    {  
       try  
       {  
          Integer.parseInt( input );  
          return true;  
       }  
       catch(Exception e )  
       {  
          return false;  
       }  
    }  
    
	public void ShowMessageDialogTEST(String s){
//		JFrame frame=new JFrame();
//		final JLabel lbl1=new JLabel();
//		lbl1.setText("my vote : ....");
//		frame.add(lbl1);
//		Object[] options={"yes, i am","no,i am not","oh, i do not know"};
//		//=========start===============
//		//show text box==============
//		String sss=(String)JOptionPane.showInputDialog(frame,
//                "Complete the sentence:\n"
//                + "\"Green eggs and...\"",
//                "Customized Dialog",
//                JOptionPane.PLAIN_MESSAGE,
//                null,
//                null,
//                null);
//		
		//show combobox=====================
//		String sss=(String)JOptionPane.showInputDialog(frame,
//      "Complete the sentence:\n"
//      + "\"Green eggs and...\"",
//      "Customized Dialog",
//      JOptionPane.PLAIN_MESSAGE,
//      null,
//      options,
//      options[1]);
		
		
		//If a string was returned, say so.
//		
//		if ((sss != null) && (sss.length() > 0)) {
//		    //lbl1.setText("my vote : "+s);
//			frmBieuQuyetMoiRaKhoiNhom f=new frmBieuQuyetMoiRaKhoiNhom(this, sss, "", "", "", 11);
//			f.setVisible(true);
//		    return;
//		}

		//If you're here, the return value was null/empty.
	//	lbl1.setText("Come on, finish the sentence!");
		//===========end=========
		
		//show co dialog---------------------------------------------------
//		final JOptionPane optionPane=new JOptionPane(s, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
//		
//		final JDialog dialog=new JDialog(frame,"heheh",true);
//		dialog.setContentPane(optionPane);
//		dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
//		dialog.addWindowListener(new WindowAdapter() {
//		    public void windowClosing(WindowEvent we) {
//		        lbl1.setText("Thwarted user attempt to close window.");
//		    }
//		});
//		optionPane.addPropertyChangeListener(
//			    new PropertyChangeListener() {
//			        public void propertyChange(PropertyChangeEvent e) {
//			            String prop = e.getPropertyName();
//
//			            if (dialog.isVisible() 
//			             && (e.getSource() == optionPane)
//			             && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
//			                //If you were going to check something
//			                //before closing the window, you'd do
//			                //it here.
//			                dialog.setVisible(false);
//			            }
//			        }
//			    });
//			dialog.pack();
//			dialog.setVisible(true);
//
//			int value = ((Integer)optionPane.getValue()).intValue();
//			if (value == JOptionPane.YES_OPTION) {
//			   // lbl1.setText("Good.");
//				frmBieuQuyetMoiRaKhoiNhom frm=new frmBieuQuyetMoiRaKhoiNhom(this, "", "", "", "", 11);
//				frm.setVisible(true);
//			} else if (value == JOptionPane.NO_OPTION) {
//				lbl1.setText("Try using the window decorations "
//			             + "to close the non-auto-closing dialog. "
//			             + "You can't!");
//			}
	}
	
	public void ShowMessage(String s){
		JFrame frame=new JFrame();
		JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
	}
	
	/**
	 * Create the frame.
	 */
	public frm_ThaoLuanNhom() {
		final frm_ThaoLuanNhom MyFrm=this;
		
		
		//== end =====
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.CENTER);
		
		JButton btnKickMember = new JButton("Kick member");
		btnKickMember.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				ShowSetTimeVoteKick();
			}
		});
		panel_1.add(btnKickMember);
		
		JPanel panel_2 = new JPanel();
		contentPane.add(panel_2, BorderLayout.WEST);
		
		JPanel panel_3 = new JPanel();
		JPanel panelTest=new JPanel();
		panel_3.setSize(200,200);
		panel_3.setLayout(new BorderLayout(0,0));
		contentPane.add(panel_3, BorderLayout.EAST);
		
		JPanel panel_4 = new JPanel();
		contentPane.add(panel_4, BorderLayout.SOUTH);
		myPanel m=new myPanel();
		panelTest.add(m);
		panel_3.add(panelTest,BorderLayout.SOUTH);
		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frmBieuQuyetMoiRaKhoiNhom frm=new frmBieuQuyetMoiRaKhoiNhom(MyFrm,"Thanh","Truc"," ", " ",10);
				frm.setVisible(true);
			}
		});
		panel_3.add(btnNewButton,BorderLayout.NORTH);
		
	}

	public  String getVoteKickMember(){
		return _voteKickMember;
	}
	
	public void setVoteKickMember(String s){
		_voteKickMember=s;
	}
}
